package com.example.baozidemo.entity;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 响应数据
 *
 * @author steed
 * @since 2020/11/11
 **/
@Data
public class Result implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 编码：0表示成功，其他值表示失败
     */
    private int code = 0;

    /**
     * 消息内容
     */
    private String msg = "success";

    /**
     * 响应数据
     */
    private Object data;

    public Result success(Object data) {
        this.setData(data);
        return this;
    }

    public Result error() {
        this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
        this.msg = "系统异常，请联系管理员";
        return this;
    }

    public Result error(String msg, Integer code) {
        this.code = code;
        this.msg = msg;
        return this;
    }

    public Result error(String msg) {
        this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
        this.msg = msg;
        return this;
    }
}
